package sysAuth

import initConfig.SysInitData

class SysDepartments {


    String deptNo;
    String name;
    String state = "1";
    Long parentId;
    int orderNum = 0;
    String marks;
    String creator ;//操作人
    String updater;//最近一次更新人

    Date dateCreated;
    Date lastUpdated;

    static constraints = {
        deptNo(nullable: false, blank: false, unique: true)
        name(nullable: false)
        state(nullable: false, blank: false)
        creator(nullable: false, blank: false)
        updater(nullable: true, blank: false)
        marks(nullable: true )
        orderNum(nullable: true )
        parentId(nullable: true, blank: false)
    }
    static mapping = {
        version false
    }

    static init(){
        if(SysDepartments.count !=0){
            return
        }
        def root = new SysDepartments(deptNo: "dept01",name: "集团",creator: SysInitData.SYS_ADMIN,state:"1")
        root.save(flush: true)

        root = new SysDepartments(deptNo: "dept02",name: "陕西控股",creator: SysInitData.SYS_ADMIN,parentId:root.id,state:"1" )
        root.save(flush: true)
        new SysDepartments(deptNo: "dept03",name: "西安分公司",creator: SysInitData.SYS_ADMIN,parentId: root.id,state:"0").save(flush: true)

    }
}
